<%@Page Language="VB"%>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<html><head>
<title>DataList Control</title>
</head>
<body bgcolor="#ffffff">
<h2>DataList Control</h2><hr />
<div id="outError" runat="server" />
<form runat="server">
  <ASP:DataList id="MyDataList" runat="server"
       CellSpacing = "2"
       SelectedItemStyle-BackColor="red"
       SelectedItemStyle-ForeColor="white"
       EditItemStyle-BackColor="yellow"
       EditItemStyle-ForeColor="black"
       DataKeyField="CateID">       
    <HeaderTemplate>
      <b>Some Books written by Khang:</b><br />
    </HeaderTemplate>
    <ItemTemplate>      
	<%# Container.DataItem("CateID") %> -  
	<%# Container.DataItem("CateName") %>
    </ItemTemplate>  
  </ASP:DataList>
</form>
<script language="vb" runat="server">
Sub Page_Load()
   If Not Page.IsPostback Then
      BindDataGrid() 
   End If
End Sub
Sub BindDataGrid()
   Dim strConnect As String  = _
	ConfigurationSettings.appSettings("conn")
   Dim strSelect As String
   strSelect = "SELECT * FROM tblCategories"
   Dim objDataReader As SqlDataReader
   Try
      Dim objConnect As New SqlConnection(strConnect)
      objConnect.Open()
      Dim objCommand As New _
	SqlCommand(strSelect, objConnect)
      objDataReader = objCommand.ExecuteReader()
    Catch objError As Exception
	outError.InnerHtml = "<b>* " & _
	"Error while accessing data</b>.<br />" _
           	& objError.Message & "<br />" & _
	objError.Source & "<p />"
       	Exit Sub 
    End Try
   MyDataList.DataSource = objDataReader
   MyDataList.DataBind()
End Sub
</script>
</body>
</html>
